package com.think.service;

import com.think.mapper.StationMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class InitService implements ApplicationListener<ApplicationStartedEvent> {
    @Autowired
    private StationMapper stationMapper;

    @Override
    public void onApplicationEvent(final ApplicationStartedEvent event) {
        //删除数据
        //        final UpdateWrapper<Station> updateWrapper = new UpdateWrapper<>();
        //        updateWrapper.ge("id", 1);
        //        this.stationMapper.delete(updateWrapper);
        //初始化数据
        this.init();
    }

    public void init() {
        //        final CsvReader reader = CsvUtil.getReader();
        //        final List<Station> list = reader.read(ResourceUtil.getUtf8Reader("/data/station.csv"), Station.class);
        //        int i = 1;
        //        for (final Station station : list) {
        //            station.setId(i);
        //            i++;
        //            this.stationMapper.insert(station);
        //        }

    }

}
